package fm.yichenet.service;

import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult;
import fm.dto.SystemUser;
import fm.entity.OrderArticleAd;
import fm.entity.OrderGood;
import fm.entity.OrderTransaction;
import fm.entityEnum.*;
import fm.exception.BizException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by 宏炜 on 2017-06-19.
 */
public interface OrderService {

    Map<String, Object> addOrder(List<OrderGood> paramsList, SystemUser user) throws Exception;

    /**
     * 创建订单
     *
     * @param articleId
     * @param adType
     * @param startTime
     * @param endTime
     */
    OrderArticleAd addArticleAdOrder(String articleId, BigDecimal totalFee, ArticleAdEnum adType, String startTime, String endTime) throws Exception;

    OrderGood cancelOrder(String orderId, SystemUser user) throws Exception;

    List<OrderGood> orderList(Integer pageSize, Integer pageNum, SystemUser user) throws Exception;


    /**
     * 生成微信交易订单并通过统一下单接口生成prepayid
     *
     * @param targetId
     * @param clientType
     * @param productType
     * @return
     */
    Object prePayOrder(String targetId, ClientTypeEnum clientType, ProductTypeEnum productType, HttpServletRequest request) throws Exception;


    /**
     * 微信支付回调
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    String notifyOrder(ClientTypeEnum clientType, ProductTypeEnum productType, HttpServletRequest request, HttpServletResponse response) throws Exception;

    /**
     * 创建一个微信支付订单记录，真正的支付需要根据此ID来发起请求
     *
     * @param targetId    订单ID列表，多个用","分割
     * @param productType 产品类型
     * @return
     * @throws BizException
     */
    OrderTransaction addOrderTransaction(String targetId, ProductTypeEnum productType) throws Exception;


    /**
     * 获取微信支付结果
     *
     * @param orderIds
     * @param productType
     * @param clientType
     * @return
     * @throws Exception
     */
    WxPayOrderQueryResult getOrderPayResult(String orderIds, ProductTypeEnum productType, ClientTypeEnum clientType) throws Exception;

    /**
     * 获取店铺订单数据
     *
     * @param pageSize
     * @param pageNum
     * @param shopId    店铺ID
     * @param minAmount 最小金额
     * @param maxAmount 最大金额
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param phone     客户手机号码
     * @return
     */
    List<OrderGood> getShopOrder(Integer pageSize, Integer pageNum, String shopId, Double minAmount,
                                 Double maxAmount, Date startTime, Date endTime, String phone, String status);

    /**
     * 统计店铺订单数量
     *
     * @param shopId
     * @param minAmount
     * @param maxAmount
     * @param startTime
     * @param endTime
     * @param phone
     * @return
     */
    long countShopOrder(String shopId, Double minAmount,
                        Double maxAmount, Date startTime, Date endTime, String phone, String status);

    /**
     * 获取订单信息
     *
     * @param orderId
     * @return
     */
    OrderGood getOrderById(String orderId);

    /**
     * 修改订单金额
     *
     * @param price
     * @param remarks
     */
    void updateOrderPrice(Double price, String remarks, String orderId) throws Exception;

    /**
     * 订单取消
     *
     * @param orderId
     */
    void cancelOrder(String orderId);

    /**
     * 订单发货
     *
     * @param orderId
     */
    void postOrder(String orderId, String expressNo);

    /**
     * 订单退款
     *
     * @param orderId
     * @param reason
     * @param amount
     */
    void refundsOrder(String orderId, String reason, Double amount);

    void refundsOrderDeal(String orderId, String reason, Integer status);

    /**
     * 修改订单
     *
     * @param orderGood
     */
    void updateOrder(OrderGood orderGood);

    /**
     * 获取个人订单
     *
     * @param userId
     * @param pageNum
     * @param pageSize
     * @return
     */
    List<OrderGood> getUserOrder(OrderEnum status, String userId, Integer pageNum, Integer pageSize);

    /**
     * 统计用户的订单数量
     *
     * @param status
     * @param userId
     * @return
     */
    long countUserOrder(OrderEnum status, String userId);

    /**
     * 获取店铺订单
     *
     * @param userId
     * @param pageNum
     * @param pageSize
     * @return
     */
    List<OrderGood> getShopOrder(OrderEnum status, String userId, Integer refundsStatus, Integer pageNum, Integer pageSize);

    /**
     * 统计商铺 的订单数量
     *
     * @param status
     * @param userId
     * @return
     */
    long countShopOrder(OrderEnum status, String userId);

    /**
     * 获取订单的完整信息，包括店铺、商品、地址、物流等信息
     *
     * @param orders
     * @return
     */
    List<Map<String, Object>> getFullInfoOrder(List<OrderGood> orders);

    /**
     * 获取交易订单
     *
     * @param orderId
     * @return
     */
    OrderTransaction getOrderTransactionById(String orderId);

    void updateOrderTransactionWxOrder(String orderId, String wxOrderId, String totalFee, ProductTypeEnum productType) throws Exception;

    void updateOrderTransactionStatus(String orderId, PayStatusEnum payStatusEnum, ProductTypeEnum productType) throws Exception;

    void updateOrderGoodStatus(String orderId, OrderEnum orderEnum) throws Exception;

    List<OrderTransaction> getOrderTransactionPayingList();

    void updateUserOrderComplete(SystemUser user, String orderId) throws BizException;

    /**
     * 获取全部自动收货订单
     *
     * @return
     */
    List<OrderGood> getAutoCompleteOrderGoodList();

    /**
     * 更新自动收货订单
     *
     * @param orderGood
     */
    void updateAutoCompleteOrderGood(OrderGood orderGood);

    /**
     * 完成订单金额结算到用户
     *
     * @param orderGood
     */
    void updateTransferCompleteOrder(OrderGood orderGood);

    /**
     * 获取可结算订单
     *
     * @return
     */
    List<OrderGood> getTransferCompleteOrderList();
}
